home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-12 | 5.3 KB | 400 lines | [TEXT/R*ch] |
- /***
- *
- * SystemTest.bob - Test the Bob compiler & interpreter
- *
- ***/
-
- class Foo { // the base class
- a, b;
- GetA();
- GetB();
- }
-
- Foo::Foo (aa, bb)
- {
- a = aa;
- b = bb;
- return this;
- }
-
- /*
- Foo::Count ( ; i)
- {
- for (i = a; i <= b; ++i)
- print(i,"\n");
- return this;
- }
- */
-
- Foo::GetA()
- {
- return a;
- }
-
- Foo::GetB ()
- {
- return b;
- }
-
-
- class Bar : Foo { // a derived class
- c;
- }
-
- Bar::Bar (aa, bb, cc)
- {
- c = cc;
- return Foo(aa, bb);
- }
-
- Bar::GetC ()
- {
- return c;
- }
-
-
- Error (test, member, value)
- {
- print("(", test, ") ", member, " = ", value, "\n");
- }
-
-
- Error1 (test, aFoo)
- {
- // print("(", test, ") aFoo->one = ", aFoo->one, "\n");
- Error(test, "aFoo->a", aFoo->GetA());
- // Error(test, "aFoo->one", aFoo);
- }
-
-
- Error2 (test, aFoo)
- {
- Error(test, "aFoo->b", aFoo->GetB());
- }
-
-
- Error12 (test, aFoo, value)
- {
- print("aFoo->a", test, "aFoo->b", " => ", value, "\n");
- }
-
-
- main (; cr, aFoo, aBar, x, y, i)
- {
- print("\n*** Starting Tests ***\n\n");
-
- // TestGC();
-
- TestBoolOps();
- TestRelOps();
- TestAssignment();
- TestIncDec();
- TestStrings();
- TestLoops();
-
- cr = "\n";
-
- x = 3;
- if (x != 3)
- Error("!=", "x", x);
-
- y = 7;
- if (y != 7)
- Error("!=", "y", y);
-
-
- if (x * y != 21)
- Error("*", "x * y", x * y);
-
- // aFoo = new Foo(x, y);
- aBar = new Bar(2, 4, 6);
- aFoo = new Bar(x, y, x + y);
-
- TestGC();
-
-
- print("\tTesting object stuff\n");
-
- if (aFoo.GetA() == x)
- ;
- else
- Error1("==", aFoo);
-
- if (aFoo->GetA() != x)
- Error1("!=", aFoo);
-
- if (aFoo->GetB() != y)
- Error2("!=", aFoo);
-
- if (aFoo.GetA() + aFoo.GetB() != x + y)
- Error12("+", aFoo, aFoo.GetA() + aFoo.GetB());
-
- if (aFoo->GetA() - aFoo->GetB() != x - y)
- Error12("-", aFoo, aFoo->GetA() - aFoo->GetB());
-
- if (aFoo->GetA() * aFoo->GetB() != x * y)
- Error12("*", aFoo, aFoo->GetA() * aFoo->GetB());
-
- if (aFoo->GetB() / aFoo->GetA() != y / x)
- Error12("/", aFoo, aFoo->GetB() / aFoo->GetA());
-
- if (aFoo->GetC() != x + y)
- print("GetC() = ", aFoo->GetC(), "\n");
-
- OK();
-
- print("*** Finished Tests ***\n");
- }
-
-
- OK ()
- {
- print("\tOK\n\n");
- }
-
-
- //
- // Test boolean operators
- //
- TestBoolOps ( ; x, y, cr)
- {
- print("\tTesting boolean operators\n");
-
- cr = "\n";
- x = 1234567;
- y = 7654321;
-
- if ((x & y) != 1098369)
- print(x, " & ", y, " = ", x & y, cr);
-
- if ((x | y) != 7790519)
- print(x, " | ", y, " = ", x | y, cr);
-
- if ((x ^ y) != 6692150)
- print(x, " ^ ", y, " = ", x ^ y, cr);
-
- if (~x != -1234568)
- print("~", x, " = ", ~x, cr);
-
- if ((x << 11) != -1766574080)
- print(x, " << ", 11, " = ", x << 11, cr);
-
- if ((y >> 5) != 239197)
- print(y, " >> ", 5, " = ", y >> 5, cr);
-
- if (!x)
- print("!", x, " = ", !x, cr);
-
- if (!nil)
- ;
- else
- print("NOT !nil = ", !nil, cr);
-
- OK();
- }
-
-
- //
- // Test relational operators
- //
- TestRelOps ( ; x, y, cr)
- {
- print("\tTesting relational operators\n");
-
- cr = "\n";
- x = 3;
- y = 7;
-
- if (y == x)
- print(x, " == ", y, cr);
-
- if (y != x)
- ;
- else
- print("NOT ", x, " != ", y, cr);
-
- if (x > y)
- print(x, " > ", y, cr);
-
- if (x >= y)
- print(x, " >= ", y, cr);
-
- if (y < x)
- print(x, " < ", y, cr);
-
- if (y <= x)
- print(x, " <= ", y, cr);
-
- OK();
- }
-
-
- class TGarbage : Bar { // a derived class
- member1, member2, member3, member4, member5;
- }
-
- TGarbage::TGarbage (aa, bb, cc)
- {
- member1 = newvector(5);
- return Bar(aa, bb, cc);
- }
-
-
- //
- // Test garbage collection
- //
- TestGC ( ; i, x)
- {
- print("\tTesting garbage collection\n");
-
- for (i = 1; i <= 2000; ++i) {
- if ((i % 10) == 0)
- print(i / 10, (i % 100) == 0 ? "\n" : " ");
- // if ((i >= 730 && i <= 740) || (i >= 1460 && i <= 1470))
- // print(".");
- x = new Bar(i, i + 1, i + i);
- }
-
- print("\tPart 2\n");
-
- // i ≤ 716 is the maximum that does not produce a
- // recursion error (MacBob 1.0ß2 & BBEdit Lite 3.0)
- for (i = 1; i <= 716; ++i)
- x = new TGarbage(x, i + 1, i + i);
-
- print("\tPart 3\n");
-
- gc();
- x = nil;
- gc();
-
- OK();
- }
-
-
- //
- // Test assignment operators
- //
- TestAssignment ( ; x, y, z, cr)
- {
- cr = "\n";
- print("\tTesting assignment operators\n");
-
- x = 1234;
- y = 4567;
-
- z = x; z += y;
- if (z != x + y)
- print("z += y = ", z, cr);
-
- z = x; z -= y;
- if (z != x - y)
- print("z -= y = ", z, cr);
-
- z = x; z *= y;
- if (z != x * y)
- print("z *= y = ", z, cr);
-
- z = x; z /= y;
- if (z != x / y)
- print("z /= y = ", z, cr);
-
- z = x; z %= y;
- if (z != x % y)
- print("z %= y = ", z, cr);
-
- z = x; z &= y;
- if (z != (x & y))
- print("z &= y = ", z, cr);
-
- z = x; z |= y;
- if (z != (x | y))
- print("z |= y = ", z, cr);
-
- z = x; z ^= y;
- if (z != (x ^ y))
- print("z ^= y = ", z, cr);
-
- OK();
- }
-
-
- //
- // Test increment/decrement operators
- //
- TestIncDec ( ; x, cr)
- {
- cr = "\n";
- print("\tTesting increment/decrement operators\n");
-
- x = 1234;
-
- if (++x != x)
- print("++x = ", x, cr);
-
- if (--x != x)
- print("--x = ", x, cr);
-
- if (x++ != x - 1)
- print("x++ = ", x, cr);
-
- if (x-- != x + 1)
- print("x-- = ", x, cr);
-
- OK();
- }
-
-
- //
- // Test strings
- //
- TestStrings ( ; x, y, i, cr)
- {
- cr = "\n";
- print("\tTesting strings\n");
-
- x = "Testing!";
- y = "!gnitseT";
-
- for (i = 0; i < sizeof(x); ++i)
- if (x[i] != y[sizeof(y) - i - 1])
- print("x[", i, "] = ", x[i], cr);
-
- OK();
- }
-
-
- //
- // Test loops
- //
- TestLoops ( ; x, y, i, cr)
- {
- cr = "\n";
- print("\tTesting loops\n");
-
- print("\t\tfor\n");
- x = -10;
- y = 10;
- for (i = x; i < y; ++i) {
- if (i != x)
- print("i = ", i, ", x = ", x, cr);
- ++x;
- }
-
- print("\t\twhile\n");
- x = -10;
- i = x;
- while (i < y)
- ++i;
-
- print("\t\tdo-while\n");
- i = x;
- do
- ++i;
- while (i < y);
-
- OK();
- }
-
-
-